<?php
/**
 * helper公共类
 */
class HelperModel {
	

	/**
	 * 设置前台用户登录session信息
	 * @param int $id member表会员ID
	 */
	function setLoginSession($id,$nickname=''){
		$result = DB('member')->field('id,username,nickname,type')->where("id={$id}")->find();
		if($nickname)
		    $result['nickname'] = $nickname;
        $_SESSION['member'] = $result;
	}
			

	/** 过滤掉非UTF-8字符
	 *   @param  String  $ostr
	 *   @return String
	 */
	function filter_utf8_char($text){
	    $clean_text = "";
	
	    // Match Emoticons
	    $regexEmoticons = '/[\x{1F600}-\x{1F64F}]/u';
	    $clean_text = preg_replace($regexEmoticons, '', $text);
	
	    // Match Miscellaneous Symbols and Pictographs
	    $regexSymbols = '/[\x{1F300}-\x{1F5FF}]/u';
	    $clean_text = preg_replace($regexSymbols, '', $clean_text);
	
	    // Match Transport And Map Symbols
	    $regexTransport = '/[\x{1F680}-\x{1F6FF}]/u';
	    $clean_text = preg_replace($regexTransport, '', $clean_text);
	
	    // Match Miscellaneous Symbols
	    $regexMisc = '/[\x{2600}-\x{26FF}]/u';
	    $clean_text = preg_replace($regexMisc, '', $clean_text);
	
	    // Match Dingbats
	    $regexDingbats = '/[\x{2700}-\x{27BF}]/u';
	    $clean_text = preg_replace($regexDingbats, '', $clean_text);
	    
	    // 过滤掉emoji表情
	    $clean_text = self::filterEmoji($clean_text);
	
	    return $clean_text;
	}
	
	
	// 过滤掉emoji表情
	function filterEmoji($str)
	{
	    $str = preg_replace_callback(
	        '/./u',
	        function (array $match) {
	            return strlen($match[0]) >= 4 ? '' : $match[0];
	        },
	        $str);
	
	    return $str;
	}
}